/**
 * 上传记录 管理模块
 */

const router = require('koa-router')()
const UploadRecord = require('./../models/uploadRdSchema')
const util = require('./../utils/util')
const fs = require('fs')
const path = require('path')

router.prefix('/upload')

// 获取上传记录列表
router.get('/records', async (ctx) => {
    try {
        const list = await UploadRecord.find({}, { _id: 0 })
        ctx.body = util.success({
            list
        })
    } catch (error) {
        ctx.body = util.fail(`查询异常:${error.stack}`)
    }
})

// 写到python后端去了
// // 下载文件 
// router.get('/download/:folderPath/:fileName', async (ctx) => {
//     const { folderPath, fileName } = ctx.params;
//     const filePath = path.join(__dirname, '..', '..', 'model_pred', 'uploads_data', folderPath, fileName);
//     if (!fs.existsSync(filePath)) {
//         ctx.status = 404;
//         ctx.body = util.fail('文件不存在');
//         return;
//     }
//     ctx.set('Content-Type', 'text/csv');
//     ctx.set('Content-Disposition', `attachment; filename=${encodeURIComponent(fileName)}`);
//     ctx.body = fs.createReadStream(filePath);
// });



module.exports = router